package com.rop.znyx.product.controller;

import com.rop.znyx.common.result.Result;
import com.rop.znyx.product.service.FileUploadService;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @Title: FileUploadController
 * @Author Rop
 * @Date 2023/6/24 21:02
 * @description: OSS文件上传
 */

@Api(tags = "文件上传接口")
@RestController
@RequestMapping("admin/product")
@RequiredArgsConstructor

public class FileUploadController {

    private final FileUploadService fileUploadService;

    @ApiOperation("图片上传")
    @PostMapping("fileUpload")
    public Result<String> fileUpload(MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        String url = fileUploadService.fileUpload(file);
        return Result.ok(url);
    }
}
